package top.chj.day16.dateclass;

import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.temporal.Temporal;
import java.time.temporal.TemporalAdjuster;
import java.time.temporal.TemporalAdjusters;

/**
 * @Auther:小陈的Java
 * 需求：假设一个员工发工资是每个月的15号，如果15号是周六或者周日，改为下周一发
 */
public class PayDayAdjuster implements TemporalAdjuster {
    @Override
    public Temporal adjustInto(Temporal temporal) {
        LocalDate localDate = LocalDate.from(temporal);
        LocalDate payDate = localDate.withDayOfMonth(15);
        if(payDate.getDayOfWeek()== DayOfWeek.SUNDAY || payDate.getDayOfWeek()==DayOfWeek.SATURDAY){
            payDate = payDate.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
        }
        return payDate;
    }
    public static void main(String[] args) {
        LocalDate localDate = LocalDate.of(2022, 5, 5);
        LocalDate payDate = LocalDate.from(new PayDayAdjuster().adjustInto(localDate));
        System.out.println(payDate);
    }
}
